package com.aaa.service.sas.Impl;


import com.aaa.dao.sas.TSasRecordDetailsMapper;
import com.aaa.dao.sas.TSasRecordMapper;
import com.aaa.entity.MyPage;
import com.aaa.entity.sas.*;
import com.aaa.service.sas.TSasRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * (TSasRecord)表服务实现类
 *
 * @author makejava
 * @since 2022-11-04 01:15:38
 */
@Service
public class TSasRecordServiceImpl implements TSasRecordService {
   @Autowired
   private TSasRecordMapper tSasRecordMapper;
   @Autowired
   private TSasRecordDetailsMapper tSasRecordDetailsMapper;

   @Override
   public Boolean checkTel(TSasRecord tSasRecord) {
      int i = tSasRecordMapper.selectCount(tSasRecord);
      return i==0;
   }

   @Override
   public int addRecord(TSasRecord tSasRecord) {
      tSasRecord.setCreatetime(new Date());
      int insert = tSasRecordMapper.insert(tSasRecord);
      return tSasRecord.getId();
   }

   @Override
   public PageInfo queryAll(MyPage page, RecordMsg recordMsg) {
      PageHelper.startPage(page.getPage(),page.getLimit());
      List<RecordMsg> recordMsgs = tSasRecordMapper.queryAll(recordMsg);
      PageInfo pageInfo = new PageInfo(recordMsgs);
      return pageInfo;
   }

   @Override
   public Boolean delRecord(Integer id) {
      int i=-1;
      TSasRecordDetails tSasRecordDetails = new TSasRecordDetails();
      tSasRecordDetails.setRecordid(id);
      int i1 = tSasRecordDetailsMapper.selectCount(tSasRecordDetails);
      System.out.println("该用户写了"+i1+"道题SAS");
      if (i1!=20){
         i = tSasRecordMapper.deleteByPrimaryKey(id);
      }
      return i>0?true:false;
   }

   @Override
   public PageInfo queryDetails(MyPage page, Integer id) {
      PageHelper.startPage(page.getPage(),page.getLimit());
      List<Map<String,Object>> listmap = tSasRecordMapper.queryDetails(id);
      PageInfo pageInfo = new PageInfo(listmap);
      return pageInfo;
   }

   @Override
   public PageInfo statistics(MyPage page, StatisticsMsg statisticsMsg) {
      PageHelper.startPage(page.getPage(),page.getLimit());
      List<StatisticsMsg> statisticsMsgs= tSasRecordMapper.statistics(statisticsMsg);
      PageInfo pageInfo = new PageInfo(statisticsMsgs);
      return pageInfo;
   }

   @Override
   public PageInfo statisticsTu(MyPage page) {
      PageHelper.startPage(page.getPage(),page.getLimit());
      List<StatisticsTu> statisticsTu= tSasRecordMapper.statisticsTu();
      PageInfo pageInfo = new PageInfo(statisticsTu);
      return pageInfo;
   }
}
